<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>属性的获取方法与设置方法</title>
</head>

<body>
  <script>

    const next = "next"
    const serialnum = {
      _n: 0,
      get [next]() {
        return this._n++;
      },
      set [next](n) {
        if (n >= this._n) this._n = n;
        else throw new Error('错误')
      }
    }
    serialnum[next] = 10
    console.log(serialnum[next]);
    console.log(serialnum.next);
    console.log(serialnum.next);
    console.log(serialnum[next]);
  </script>
</body>

</html>